﻿using CommunityToolkit.Mvvm.ComponentModel;
using MultiCommunication.Views;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Security.RightsManagement;
using System.Text;
using System.Threading.Tasks;

namespace MultiCommunication.ViewModels
{
    public partial class MainWindowViewModel 
    {
        public ObservableCollection<TabItemViewModel> TabItems {  get; set; }

        private TabItemViewModel _selectedTabItem;
        public TabItemViewModel SelectedTabItem 
        { 
            get { return _selectedTabItem;}
            set 
            {
                if(_selectedTabItem != value)
                {
                    _selectedTabItem = value;
                    OnPropertyChanged(nameof(SelectedTabItem));

                    if (_selectedTabItem != null) 
                    {
                        Mediator.currentTabName = _selectedTabItem.TabName;
                    }
                }        
            } 
        }

        public MainWindowViewModel()
        {
            TabItems = new ObservableCollection<TabItemViewModel>
            {
                new TabItemViewModel{ TabName="SerialPort",Content=new SerialPortView()},
                new TabItemViewModel{ TabName="Tcp",Content=new TcpView()},
                new TabItemViewModel{ TabName="Modbus",Content=new ModbusView()},
                new TabItemViewModel{ TabName="CAN",Content=new CANView()},
            };
        }


        // INotifyPropertyChanged实现
        public event PropertyChangedEventHandler PropertyChanged;

        protected virtual void OnPropertyChanged(string propertyName)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}
